﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace pwestcott.Util.Tests.Essence.CompareTo
{
    [TestFixture]
    public class CompareToOrder
    {
        class OrderChecker : IComparable<OrderChecker>
        {
            public static int CurrentOrder;
            public readonly int Order;

            public OrderChecker(int expectedOrder)
            {
                Order = expectedOrder;
            }

            public int CompareTo(OrderChecker other)
            {
                if (Order == CurrentOrder++)
                    return 0;
                else
                    return -1;
            }
        }

        class TestEssence
        {
            [Essence(Order = 1)] OrderChecker first = new OrderChecker(1);
            [Essence(Order = 2)] OrderChecker second = new OrderChecker(2);
            [Essence(Order = 3)] OrderChecker third = new OrderChecker(3);
        }

        [Test]
        public void Test()
        {
            OrderChecker.CurrentOrder = 1;
            Assert.AreEqual(0, Essence<TestEssence>.CompareToStatic(new TestEssence(), new TestEssence()));
            Assert.AreEqual(4, OrderChecker.CurrentOrder);
        }

        [Test]
        public void Fast()
        {
            var f = Essence<TestEssence>.Fast;
        }
    }
}
